package ac.github.os.internal.core.action.store

import ac.github.os.internal.core.condition.callVoid
import ac.github.os.internal.core.config.StringConfig
import ac.github.os.internal.core.config.get
import ac.github.os.internal.core.trigger.PlayerTrigger
import ac.github.os.internal.session.Cache
import ac.github.os.internal.session.Session
import taboolib.common.platform.Awake

abstract class PlayerStoreAction : StoreAction() {

    override val namespace: String
        get() = "pstore:$name"

    override fun onExecute(session: Session, cache: Cache, config: StringConfig) {
        val key = config.get<String>("k") ?: return
        val value = config.get<String>("v") ?: return
        session.callVoid<PlayerTrigger> {
            eval(it.player.name + "." + key, value).eval()
        }

    }
}


@Awake
class PlayerStoreAddAction : PlayerStoreAction() {
    override val name: String
        get() = "add"

    override fun eval(key: String, value: Any) = StoreAdd(key, value)
}

@Awake
class PlayerStoreSubtractAction : PlayerStoreAction() {
    override val name: String
        get() = "sub"

    override fun eval(key: String, value: Any) = StoreSubtract(key, value)
}

@Awake
class PlayerStoreSetAction : PlayerStoreAction() {
    override val name: String
        get() = "set"

    override fun eval(key: String, value: Any) = StoreSet(key, value)
}

@Awake
class PlayerStoreMultiplyAction : PlayerStoreAction() {
    override val name: String
        get() = "mult"

    override fun eval(key: String, value: Any) = StoreMultiply(key, value)
}

@Awake
class PlayerStoreDivisionAction : PlayerStoreAction() {
    override val name: String
        get() = "div"

    override fun eval(key: String, value: Any) = StoreDivision(key, value)
}